// @ts-ignore
import JSEncrypt from "jsencrypt/bin/jsencrypt.min";

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey =
  "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnJ3u/GTShv4dg9yboC72\n" +
  "i41nmo41AEPcWz6+pcqmDdY0fJqcAq4vlPk7wd6npduR7PAWR0On2ViyZr0sYfJE\n" +
  "z+dGEx7Zd+mgrBEhf+e4F0E4JAUQuKjyam7lsU89bB+FWMG/0Xu2gvKiYko/7jBW\n" +
  "1TUfUikQMTbonbqP9g7/VkHDL6fU2MTvqyX9xmf5FFAf+hLOY3vl7jvBcLUtjrGK\n" +
  "YuBTxof0iO2LjaoFod+B3fIiRwqhNZL4obXweGhbmbHEU/gKZyCjF8IVSTacB48X\n" +
  "+g5UZmQktwemmiq47ndr1kxaDBg0Ua7hcAVpKM79fUIlwhufuJVbYiR4j0UVoNcz\n" +
  "qQIDAQAB";

const privateKey =
  "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCcne78ZNKG/h2D\n" +
  "3JugLvaLjWeajjUAQ9xbPr6lyqYN1jR8mpwCri+U+TvB3qel25Hs8BZHQ6fZWLJm\n" +
  "vSxh8kTP50YTHtl36aCsESF/57gXQTgkBRC4qPJqbuWxTz1sH4VYwb/Re7aC8qJi\n" +
  "Sj/uMFbVNR9SKRAxNuiduo/2Dv9WQcMvp9TYxO+rJf3GZ/kUUB/6Es5je+XuO8Fw\n" +
  "tS2OsYpi4FPGh/SI7YuNqgWh34Hd8iJHCqE1kvihtfB4aFuZscRT+ApnIKMXwhVJ\n" +
  "NpwHjxf6DlRmZCS3B6aaKrjud2vWTFoMGDRRruFwBWkozv19QiXCG5+4lVtiJHiP\n" +
  "RRWg1zOpAgMBAAECggEAUGX26BQtyuSqbCWUsm9JWyxU8g9sf91WQnT8U4mrItFC\n" +
  "knCgA/Q9MuGa3pQZRdhomdRJ6318reONeZZFMWa4Em4sF+avRp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Ju2RZ6rUQKBgBk9yE3INK9DL9i0vhdn\n" +
  "MqpuU2NYZMqu7DFpioMg+I0c+a9fhniDpI+VmmiWLTtsgXGMsgc8dwT9sLfCXrfU\n" +
  "MmZcFLwku7zuSiFpIXXKgTSK05nn2P2jF6YwmjGxaoU22nB6SYziIYf+JlCoh/iX\n" +
  "hdWQSqqfNByDfZMnLAgS+ao2";

// 加密
export function encrypt(txt: string | number) {
  const encryptor = new JSEncrypt();
  encryptor.setPublicKey(publicKey); // 设置公钥
  return encryptor.encrypt(txt); // 对数据进行加密
}

// 解密
export function decrypt(txt: string) {
  const encryptor = new JSEncrypt();
  encryptor.setPrivateKey(privateKey); // 设置私钥
  return encryptor.decrypt(txt); // 对数据进行解密
}
